<template>
    <div>
        <div class="tip">
            <span style="color: #409EFF"><i class="el-icon-warning"> 注意</i></span><br/>
            &nbsp;&nbsp;1、公钥版本号、会话存档secret请到企业微信后台复制粘贴到本系统对应位置，填写错误可能导致会话存档功能失效。<br/>
            &nbsp;&nbsp;2、配置成功后，不能在企微后台修改相关配置信息；如果确实需要修改，请保持两边信息一致，否则将解密失败，将无法获取企微会话的内容。<br/>
            &nbsp;&nbsp;3、会话存档配置必须严格按照操作流程进行配置，如果未按操作流程进行配置会导致配置失败此时需要按照操作步骤重新配置。
            <el-link type="primary" :underline="false" @click="instructions">操作步骤。</el-link>
            <br/>
            &nbsp;&nbsp;4、可设置提醒，在系统解密失败时通过首页快捷消息和短信去提醒预设的管理员及时在系统进行会话存档重新配置。
        </div>
        <div>
            <el-form ref="form" :model="archive" label-width="249px">

                <el-form-item label="可信IP配置：" required inline->
                    <el-col :span="18">
                        <el-input v-model="archive.sessionIp" disabled/>
                    </el-col>
                    <el-col :span="2">
                        <el-button style="font-size: 20px;padding-left: 10px" type="text" icon="el-icon-copy-document"
                                   @click="copy(archive.sessionIp)"/>
                        <el-tooltip class="item" effect="dark"
                                    content="将IP地址填入【企业微信后台-管理工具-会话内容存档-可信IP地址】中，以保证会话内容存档正常使用" placement="top">
                            <el-button style="font-size: 20px" type="text" icon="el-icon-warning-outline"></el-button>
                        </el-tooltip>
                    </el-col>
                </el-form-item>

                <el-form-item label="消息加密公钥：" required>
                    <el-col :span="18">
                        <el-input type="textarea" v-model="archive.sessionPublicKey" :autosize="{ minRows: 4, maxRows: 10}"
                                  disabled/>
                    </el-col>
                    <el-col :span="1" style="padding-left: 10px">
                        <el-link type="primary" :underline="false" @click="getKey">生成</el-link>
                        <el-link type="primary" :underline="false" @click="copy(archive.sessionPublicKey)">复制</el-link>
                    </el-col>
                </el-form-item>

                <el-form-item label="公钥版本号：" required>
                    <el-col :span="18">
                        <el-input v-model="archive.publicKeyVersion"/>
                    </el-col>
                    <el-col :span="1">
                        <el-tooltip class="item" effect="dark"
                                    content="消息加密公钥配置完成后，将【企业微信后台-管理工具-会话内容存档-消息加密公钥版本号】写在此处，填写错误将无法使用会话存档功能。" placement="top">
                            <el-button style="font-size: 20px;padding-left: 10px" type="text" icon="el-icon-warning-outline"></el-button>
                        </el-tooltip>
                    </el-col>
                </el-form-item>

                <el-form-item label="会话存档secret：" required>
                    <el-col :span="18">
                        <el-input v-model="archive.sessionSecret"/>
                    </el-col>
                    <el-col :span="1">
                        <el-tooltip class="item" effect="dark"
                                    content="前往【企业微信后台-管理工具-会话内容存档-Secret】获取" placement="top">
                            <el-button style="font-size: 20px;padding-left: 10px" type="text" icon="el-icon-warning-outline"></el-button>
                        </el-tooltip>
                    </el-col>
                </el-form-item>

                <!--<el-form-item label="设置获取消息失败预警提醒：">
                    所提醒管理员手机号：{{ sessionPhone }}
                    <br/>
                    <el-checkbox-group v-model="sessionRemindType">
                        <el-checkbox label="1" name="type">首页快捷消息提醒</el-checkbox>
                        <el-checkbox label="2" name="type">短信提醒</el-checkbox>
                    </el-checkbox-group>
                </el-form-item>-->
                <el-form-item>
                    <el-button type="primary" @click="addSessionArchive">保存</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                archive: {
                    sessionArchiveId: '',
                    sessionIp: '',
                    sessionPublicKey: '',
                    publicKeyVersion: '',
                    sessionSecret: '',
                    sessionRemindType: '',
                },
                sessionRemindType: [],
                sessionPhone: '',
            }
        },
        mounted() {
            this.initData()
        },
        methods: {
            instructions(){
                window.open("http://scrm.zzxapps.com/#/scrm_views/views/riskControl/session_archive/instructions")
            },
            initData(){
                let that = this;
                this.$request('/api/sessionArchive/getById/1_0?id=' + this.$store.getters.getUserInfo.companyId, '' , 'POST').then((data) => {
                    that.archive = data.data;
                    if (data.data.sessionRemindType != null && data.data.sessionRemindType != undefined){
                        that.sessionRemindType = data.data.sessionRemindType.split(',')
                    }
                })
            },
            // 点击复制
            copy(data) {
                let url = data;
                let oInput = document.createElement('input');
                oInput.value = url;
                document.body.appendChild(oInput);
                oInput.select(); // 选择对象;
                document.execCommand("Copy"); // 执行浏览器复制命令
                this.$message({
                    message: '复制成功！',
                    type: 'success'
                });
                oInput.remove()
            },
            getKey(){
                let that = this;
                this.$request('/api/sessionArchive/publicKey/1_0?id=' + this.$store.getters.getUserInfo.companyId, '' , 'POST').then((data) => {
                    that.archive.sessionPublicKey = data.data.sessionPublicKey;
                })
            },
            addSessionArchive(){
                let that = this;
                that.archive.sessionRemindType = that.sessionRemindType.join(',')
                this.$request('/api/sessionArchive/addSessionArchive/1_0', that.archive , 'POST').then((data) => {
                    this.$message({
                        message: '保存成功！',
                        type: 'success'
                    });
                })
            },
        }
    }
</script>

<style scoped>

</style>
